<?php

namespace App\Http\Requests\Entity\Pm;

use App\Http\Requests\Request;

class PriceRequest extends Request
{

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            case 'GET':
            case 'DELETE':
                {
                    return [];
                }
            // Crate
            case 'POST':
                {
                    return [
                        'name'               => 'required|max:100',
                        'title'              => 'required|max:100',
                        'short_desc'         => 'required|max:100',
                        'prices'             => 'required|numeric|max:100',
                        // 'pmtag_id'           => 'max:100',
                        // 'metering_period_id' => 'required_with:pmtag_id|max:100',
                        'startdate'          => 'required|date',
                        'enddate'            => 'required|date',
                        'type'               => 'required',
                        'expiry_date_id'     => 'required_if:type,2',
                    ];
                }
            // UPDATE
            case 'PUT':
            case 'PATCH':
                {
                    // $id = $this->route('prices');
                    return [
                        'name'               => 'required|max:100',
                        'title'              => 'required|max:100',
                        'short_desc'         => 'required|max:100',
                        'prices'             => 'required|numeric|max:100',
                        // 'pmtag_id'           => 'max:100',
                        // 'metering_period_id' => 'required_with:pmtag_id|max:100',
                        'startdate'          => 'required|date',
                        'enddate'            => 'required|date',
                        'type'               => 'required',
                        'expiry_date_id'     => 'required_if:type,2'
                    ];
                }
            default:
                break;
        }
    }
    public function messages()
    {
        return [
            'name.required'       => '名称 不能为空',
            'short_desc.required' => '描述 不能为空',
            'title.required'       => '标题 不能为空',
            'prices.required'     => '价格 不能为空',
            'startdate.required'  => '开始时间 不能为空',
            'enddate.required'  => '结束时间 不能为空',
            'type.required'  => '定价类型 不能为空',
            'expiry_date_id.required_if'  => '当单点定价类型为"单点定价"时,单点定价有效期不能为空',
        ];
    } 
}
